import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

export enum ShowType {
    /**初始化 */
    ST_Init = 0,
    /**分帧加载 */
    ST_FrameLoading = 1,
}

@ccclass('GameManager')
export class GameManager extends Component {

    /**开始UI，选择展示什么东西 */
    public UIStart:Node;
    /**玩耍UI */
    public UIPlaying:Node;

    /**分帧加载展示节点 */
    public UIFrameLoad:Node;
    onLoad(){
        GameManager._instance = this;

        this.UIStart = this.node.getChildByPath("UI/UIStart");
        this.UIPlaying = this.node.getChildByPath("UI/UIPlaying");
        this.UIFrameLoad = this.node.getChildByPath("UI/UIFrameLoad");

        GameManager.instance.CurShowType = 0;
    }
    start() {
    }
    update(deltaTime: number) {   
    }

    static _instance: GameManager;
    static get instance() {
        if (this._instance) {
            return this._instance;
        }
        this._instance = new GameManager();
        return this._instance;
    }

    public HideAllUI(){
        this.UIPlaying.active = false;
        this.UIStart.active = false;
        this.UIFrameLoad.active = false;

    }
    
    private curShowType: ShowType = ShowType.ST_Init;
    get CurShowType() { return this.curShowType; }
    set CurShowType(value: ShowType) {
        this.HideAllUI();
        this.UIPlaying.active = true;
        switch (value + "") {
            case ShowType.ST_Init + "":
                this.UIPlaying.active = false;
                this.UIStart.active = true;
                break;
            case ShowType.ST_FrameLoading + "":
                console.log("==================");
                this.UIFrameLoad.active = true;
                break;
            default:
                console.log("格式错误",typeof(value),typeof(ShowType.ST_FrameLoading));
                break;
        }
        this.curShowType = value;
    }
}

